package com.plan.enums;

import com.plan.base.util.DateUtil;

import java.time.LocalDate;
import java.time.Period;
import java.util.Date;

/**
 * 年龄阶段
 *
 * @author zcl
 */
public enum AgeLevelEnum {
    NONE(0, "不区分"),
    BEFORE_SCHOOL(1, "学前"),
    KINDERGARTEN(2, "幼儿园"),
    PRIMARY_SCHOOL(3, "小学"),
    JUNIOR_SCHOOL(4, "初中"),
    HIGH_SCHOOL(5, "高中"),
    UNIVERSITY(6, "大学"),
    SOCIETY(7, "社会"),
    OTHER(99, "其它"),
    ;

    AgeLevelEnum(int level, String desc) {
        this.level = level;
        this.desc = desc;
    }

    private int level;
    private String desc;

    public int getLevel() {
        return level;
    }

    public String getDesc() {
        return desc;
    }

    public static int getLevelForBirthday(Date birthday) {
        LocalDate birthdayL = DateUtil.dateToLocalDate(birthday);
        LocalDate now = LocalDate.now();
        int age = Period.between(birthdayL, now).getYears();
        int birthMonth = birthdayL.getMonthValue();
        int birthDay = birthdayL.getDayOfMonth();

        // 如果生日在 9 月 1 日之后，年龄减 1
        if (birthMonth > 9 || (birthMonth == 9 && birthDay > 1)) {
            age--;
        }
//        if (age < 3) {
//            return AgeLevelEnum.BEFORE_SCHOOL.level;
//        }
        // 幼儿园阶段 (3 - 6岁)
        if (age < 6) {
            return AgeLevelEnum.KINDERGARTEN.level;
        }
        // 小学阶段 (6 - 12岁)
        if (age >= 6 && age < 12) {
            return AgeLevelEnum.PRIMARY_SCHOOL.level;
        }
        // 初中阶段 (12 - 15岁)
        if (age >= 12 && age < 15) {
            return AgeLevelEnum.JUNIOR_SCHOOL.level;
        }
        // 高中阶段 (15 - 18岁)
        if (age >= 15 && age < 18) {
            return AgeLevelEnum.HIGH_SCHOOL.level;
        }
        // 大学阶段 (18岁及以上)
        if (age >= 18) {
            return AgeLevelEnum.UNIVERSITY.level;
        }
        if (age >= 22) {
            return AgeLevelEnum.SOCIETY.level;
        }
        return AgeLevelEnum.OTHER.level;
    }
}
